// 使用Promise封装wx.request  ， axios的封装原理 （XMLHttpRequest、Promise）

import {
	BASE_URL,
	ID,
	KEY
} from '@/config/index.js'

function $http({
	url,
	method = "GET",
	data = {}
}) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + '/1.1' + url,
			method,
			data,
			header: {
				"X-LC-Id": ID,
				"X-LC-Key": KEY,
				"Content-Type": "application/json"
			},
			success: (res) => {
				resolve(res)
			},
			fail: (err) => {
				reject(err)
			}
		})
	})
}

function $get(url, data) {
	return $http({
		url,
		data
	})
}

function $post(url, data) {
	return $http({
		url,
		data,
		method: 'POST'
	})
}

export {
	$http,
	$get,
	$post
}
